﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace MMITWeb.Infrastructure.CustomValidators
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property,AllowMultiple=true, Inherited=true)]
    public class DecimalValidatorAttribute : ValidationAttribute
    {
        private decimal minValue = 0.01M;
        private decimal maxValue = 9999999.99M;

        public DecimalValidatorAttribute()
            : base("Value is not in a valid range")
        {

        }

        public override bool IsValid(object value)
        {
            var p = (decimal)value;
            if (p < this.minValue || p > this.maxValue)
                return false;
            return true;
        }
    }
}